﻿using Furion.DependencyInjection;
using IMES.Entity;
using Mapster;

namespace IMES.BLL
{
    public class ClothSizeRep : BaseRepository<BsClothsize>, ITransient
    {
        /// <summary>
        /// 获取所有尺码
        /// </summary>
        /// <returns></returns>
        public List<ClothSizeVO> GetAllSize()
        {
            var dtlist=Context.Queryable<BsClothsize>()
                .InnerJoin<BsCustomer>((a,b)=>a.CustomerCode==b.Code)
                .Where((a,b)=>!a.IsDeleted)
                .OrderBy((a, b) => new { a.CustomerCode, a.SortID }, SqlSugar.OrderByType.Asc)
                .Select((a,b)=>new ClothSizeVO()
                {
                    Id = a.Id,
                    CreateTime = a.CreateTime,
                    Creator = a.Creator,
                    CustomerCode = a.CustomerCode,
                    CustomerName = b.Name,
                    Editor = a.Editor,
                    EditTime = a.EditTime,
                    IsDeleted = a.IsDeleted,
                    NewSortID = a.SortID,
                    SortID = a.SortID,
                    Remark = a.Remark,
                    Size = a.Size,
                    Usable = a.Usable,
                })
                .ToList();
            return dtlist;
        }

        /// <summary>
        /// 尺码排序更新处理
        /// </summary>
        /// <param name="changedList"></param>
        public void SizeSortUpdate(List<ClothSizeVO> changedList)
        {
            var uplist = changedList.Adapt<List<BsClothsize>>();
            Context.Updateable(uplist).ExecuteCommand();
        }
    }
}
